package admin.forms.config;

import java.util.TreeMap;

import javax.servlet.http.HttpServletRequest;

import models.config.ServiceConfigModel;

public class ServiceConfigForm {
	public TreeMap checkValidUrlSource(HttpServletRequest request, ServiceConfigModel config) {
		TreeMap form = new TreeMap();
		TreeMap check = new TreeMap();
		String urlWhois = (String) request.getParameter("urlWhois");
		String urlIpAddress = (String) request.getParameter("urlIpAddress");
		String urlAlexa = (String) request.getParameter("urlAlexa");
		String urlGoogleRank = (String) request.getParameter("urlGoogleRank");
		String urlAgeDomain = (String) request.getParameter("urlAgeDomain");
		String urlValidator = (String) request.getParameter("urlValidator");
		
		if (urlWhois == null || urlWhois.isEmpty()) {
			check.put("urlWhois", "UrlWhois not empty.");
		} else {
			config.setUrlWhois(urlWhois);
		}
		
		if (urlIpAddress == null || urlIpAddress.isEmpty()) {
			check.put("urlIpAddress", "UrlIpAddress is not empty.");
		} else {
			config.setUrlIpAddress(urlIpAddress);
		}
		
		if (urlAlexa == null || urlAlexa.isEmpty()) {
			check.put("urlAlexa", "UrlAlexa is not empty.");
		} else {
			config.setUrlAlexa(urlAlexa);
		}
		
		if (urlGoogleRank == null || urlGoogleRank.isEmpty()) {
			check.put("urlGoogleRank", "UrlGoogleRank is not empty.");
		} else {
			config.setUrlGoogleRank(urlGoogleRank);
		}
		
		if (urlAgeDomain == null || urlAgeDomain.isEmpty()) {
			check.put("urlAgeDomain", "UrlAgeDomain is not empty.");
		} else {
			config.setUrlAgeDomain(urlAgeDomain);
		}
		
		if (urlValidator == null || urlValidator.isEmpty()) {
			check.put("urlValidator", "urlValidator is not empty.");
		} else {
			config.setUrlValidator(urlValidator);
		}
		
		form.put("checkValid", check);
		form.put("config", config);
		
		return form;
	}
	
}
